package com.test.mooan.labama.dialog_boom.ln_boom;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.google.android.material.bottomsheet.BottomSheetDialog;
import com.test.mooan.labama.R;
import com.test.mooan.labama.activity_fragment_boom.base_boom.BaseActivity_boom;
import com.test.mooan.labama.bean_boom.config_info_boom.CountryInfo_boom;
import com.test.mooan.labama.bean_boom.product.Product;
import com.test.mooan.labama.utils_boom.Stringutil_boom;
import com.test.mooan.labama.utils_boom.helper_boom.UserInfoHelper_boom;
import com.test.mooan.labama.utils_boom.http_boom.HttpManager_boom;
import com.test.mooan.labama.adapter_boom.WltActTypeListAdapter_Fr_boom;
import com.test.mooan.labama.view_boom.widget_boom.BoomEditText;


public class AddBkActDialog_Cote_boom extends BottomSheetDialog {

    private BaseActivity_boom baseActivity;
    private TextView prefix1Tv, prefix2Tv;
    private BoomEditText mobile1Et, mobile2Et;
    private TextView changeTv;

    private ImageView accountTypeIv;
    private TextView accountTypeTv;

    private WltActTypeListAdapter_Fr_boom walletAccountTypeListAdapter;

    private String walletType = "WAVE";

    public static final String WalletType_Wave ="WAVE", WalletType_Others ="OTHERS";
    
    private final String pageTag = "ADD_ACCOUNT_1";

    private final Product product;

    public AddBkActDialog_Cote_boom(@NonNull Context context, Product product) {
        super(context, R.style.BottomSheetDialogStyle);
        if (context instanceof BaseActivity_boom) baseActivity = (BaseActivity_boom) context;
        if (product==null) product = Product.gtInstance(null);
        this.product = product;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_add_bk_act_cote_boom);
        getWindow().setBackgroundDrawableResource(R.color.trans);
        getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
        setCancelable(false);
        setCanceledOnTouchOutside(false);
        init();
    }

    private void init(){

        prefix1Tv = findViewById(R.id.dialog_add_account_cote_tv_prefix_1);
        prefix2Tv = findViewById(R.id.dialog_add_account_cote_tv_prefix_2);
        mobile1Et = findViewById(R.id.dialog_add_account_cote_et_mobile_1);
        mobile2Et = findViewById(R.id.dialog_add_account_cote_et_mobile_2);
        changeTv = findViewById(R.id.dialog_add_account_cote_tv_change);
        accountTypeIv = findViewById(R.id.dialog_add_account_cote_iv_account_type);
        accountTypeTv = findViewById(R.id.dialog_add_account_cote_tv_account_type);

        mobile1Et.stEventWord(pageTag+"_WAVE_PHONE_INPUT");
        mobile1Et.stEventWord(pageTag+"_WAVE_PHONE_CONFIRM_INPUT");

//        mobile1Et.setOnFocusChangeListener((v, hasFocus) -> {
//            if (hasFocus){
//                if (walletType.equalsIgnoreCase(WalletType_Wave))
//                    UserInfoHelper_boom.gInstance().addEventPoint((pageTag+"_WAVE_PHONE_INPUT"));
//                else
//                    UserInfoHelper_boom.gInstance().addEventPoint((pageTag+"_OTHER_PHONE_INPUT"));
//            }else{
//                if (walletType.equalsIgnoreCase(WalletType_Wave))
//                    UserInfoHelper_boom.gInstance().addEventPoint((pageTag+"_WAVE_PHONE_INPUT"),Stringutil_boom.getSafeString(mobile1Et.getText().toString()));
//                else
//                    UserInfoHelper_boom.gInstance().addEventPoint((pageTag+"_OTHER_PHONE_INPUT"),Stringutil_boom.getSafeString(mobile1Et.getText().toString()));
//            }
//        });

        String prefix = CountryInfo_boom.gInstance().gAreaCode();
        prefix1Tv.setText(prefix);
        prefix2Tv.setText(prefix);

        changeTv.setOnClickListener(v -> changeType());

        findViewById(R.id.dialog_add_bank_account_cote_ib_back).setOnClickListener(v -> dismiss());

        findViewById(R.id.dialog_add_account_cote_btn_submit).setOnClickListener(v -> {

            if (walletType.equalsIgnoreCase(WalletType_Wave))
                UserInfoHelper_boom.gInstance().addEventPoint((pageTag+"_WAVE_SAVE_CLICK"));
            else
                UserInfoHelper_boom.gInstance().addEventPoint((pageTag+"_OTHER_SAVE_CLICK"));

            String account1 = Stringutil_boom.getSafeString(mobile1Et.getText().toString());
            String account2 = Stringutil_boom.getSafeString(mobile2Et.getText().toString());
            HttpManager_boom.getInstance().bindBankAccount(account1,account2, walletType,product.gtProduct(),product.gtToken());
            dismiss();
        });

    }

    @SuppressLint("SetTextI18n")
    public void changeType(){
        if (walletType.equalsIgnoreCase(WalletType_Wave)){

            UserInfoHelper_boom.gInstance().addEventPoint((pageTag+"_OTHER_TYPE_CLICK"));

            walletType = WalletType_Others;
            accountTypeIv.setBackgroundResource(R.drawable.icon_wallet_type_fr_others);
            accountTypeTv.setText("Orange/MTN/MOOV");
            changeTv.setText("Je veux utiliser Wave");

        }else{

            UserInfoHelper_boom.gInstance().addEventPoint((pageTag+"_WAVE_TYPE_CLICK"));

            walletType = WalletType_Wave;
            accountTypeIv.setBackgroundResource(R.drawable.icon_wallet_type_fr_wave);
            accountTypeTv.setText("Wave");
            changeTv.setText("Je n'ai pas Wave");

        }
    }

    @SuppressLint("SetTextI18n")
    @Override
    public void show() {
        super.show();
        if (walletType.equalsIgnoreCase(WalletType_Wave))
            UserInfoHelper_boom.gInstance().addEventPoint(pageTag+"_START");
    }

    @Override
    public void dismiss() {
        super.dismiss();
        UserInfoHelper_boom.gInstance().addEventPoint(pageTag+"_END");
    }

}
